package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件上传数据通用性的请求 所以写到单独Controller中
 */
@RestController
@Slf4j //日志
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;//从spring中拿到阿里云oss

    //根据接口文档 设计 /upload 处理
    @PostMapping("/upload")
    public Result upload(MultipartFile image) throws IOException {
        log.info("上传文件:"+image);
        //找 aliyunOss工具类 完成文件上传
        String url = aliOSSUtils.upload(image);
        return Result.success(url);
    }
}
